package com.example.xinli.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.xinli.dao.QingxucaijiMapper;
import com.example.xinli.dao.ZhengnianlianxiMapper;
import com.example.xinli.domain.entity.Qingxucaiji;
import com.example.xinli.domain.entity.Zhengnianlianxi;
import com.example.xinli.domain.vo.QingxucaijiSubmitVo;
import com.example.xinli.domain.vo.ResponseBean;
import com.example.xinli.domain.vo.ResponseBeanEnum;
import com.example.xinli.domain.vo.ZhengnianlianxiSubmitVo;
import com.example.xinli.service.IQingxucaijiService;
import com.example.xinli.service.IZhengnianlianxiService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class QingxucaijiServiceImpl extends ServiceImpl<QingxucaijiMapper, Qingxucaiji> implements IQingxucaijiService {

    @Autowired
    QingxucaijiMapper qingxucaijiMapper;

    @Override
    public ResponseBean getAllUserQingxucaiji(String userId) {
        QueryWrapper<Qingxucaiji> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        List<Qingxucaiji> qingxucaijiList = qingxucaijiMapper.selectList(queryWrapper);
        return ResponseBean.success(qingxucaijiList);
    }

    @Override
    public ResponseBean submitQingxucaiji(QingxucaijiSubmitVo qingxucaijiSubmitVo) {
        Qingxucaiji qingxucaiji = new Qingxucaiji();
        qingxucaiji.setUserId(qingxucaijiSubmitVo.getUserId());
        qingxucaiji.setDate(qingxucaijiSubmitVo.getDate());
        qingxucaiji.setFeelingUrl(qingxucaijiSubmitVo.getFeelingUrl());
        qingxucaiji.setFeelingName(qingxucaijiSubmitVo.getFeelingName());
        qingxucaiji.setRenzhi(qingxucaijiSubmitVo.getRenzhi());
        qingxucaiji.setXingwei(qingxucaijiSubmitVo.getXingwei());
        qingxucaiji.setShengli(qingxucaijiSubmitVo.getShengli());
        qingxucaiji.setChansheng(qingxucaijiSubmitVo.getChansheng());
        qingxucaiji.setYingdui(qingxucaijiSubmitVo.getYingdui());
        qingxucaiji.setQixiao(qingxucaijiSubmitVo.getQixiao());
        qingxucaiji.setRecordId(-1);

        int res = qingxucaijiMapper.insert(qingxucaiji);
        if (res > 0) {
            return ResponseBean.success();
        }
        return ResponseBean.error(ResponseBeanEnum.ERROR);
    }
}

